﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

  <head>
      <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>能耗展示系统</title>
    <link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css" />  
    <script type="text/javascript" charset='gb2312' src="JSClass/FusionCharts.js"></script>    
    <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAA0tE6QtF1vsojmaotduPfjBRLUID8NVLvYeDqXkvBcrE-43D1dhSdxvBCLfZOjtcNy7ZSv7tIm1xOIQ"></script>
    <script type="text/javascript" src="ext/ext-base.js"></script>
    <script type="text/javascript" src="ext/ext-all.js"></script>
	<style type="text/css">
		.x-tree-node-expanded .x-tree-node-icon {background-image: url('images/layer.png') !important; }
		.x-tree-node-leaf .x-tree-node-icon {background-image: url('images/3d.png') !important; }
		.x-tree-node-collapsed .x-tree-node-icon {background-image: url('images/layer.png') !important; }
		.x-grid3-td-1 {vertical-align:middle !important;}
		.x-grid3-td-2 {vertical-align:middle !important;}
		.x-grid3-viewport {background-color: #DFE8F6 !important;}
		.x-grid3-row {border-bottom-color: #ABC7EC !important;}
		.x-grid3-row-first{border-bottom-color: #ABC7EC !important;border-top-color: #DFE8F6 !important;}
	</style>
    <script type="text/javascript">
        google.load("earth", "1");
        var chart;
        var swfchartdata;

        var kmllayerscn = ["建筑功能", "建筑年代", "建筑类型", "建筑高度", 
        //"建筑总能耗", 
        "建筑年单位面积能耗"];
        var kmllayersen = ["jzgn", "jznd", "jzlx", "jzcs", 
        //"建筑总能耗", 
        "jzndwnh"];
var kmllayerslength = kmllayerscn.length;
var ge = null;
var ds;
var numrecords = 10;
var nodesRoot = new Ext.tree.TreeNode({ text: '建筑专题' });

for (var n = 0; n < kmllayerslength; n++) {
    var nodeToAdd = new Ext.tree.TreeNode({
        text: kmllayerscn[n],
        checked: false,
        value:kmllayersen[n]
    });
    //nodeToAdd.appendChild(new Ext.tree.TreeNode({hidden: true}));
    nodesRoot.appendChild(nodeToAdd);
}

var kmlobject;

var tree = new Ext.tree.TreePanel({
					border: false,
			        useArrows:true,
			        rootVisible:false,
			        animate:true,
			        enableDD:true,
			        containerScroll: true,
			        root: nodesRoot,
			        listeners: {
			        'checkchange': treeCheckChange
			        }
			    }
			    );	
function modifyballoon(){
    var balloon = ge.getBalloon();
    balloon.setContentString("<iframe width='400px' height='400px' src='about:blank'></iframe>");

}
var functionsGridData = [
	['面积街道统计','<img src="images/directional_arrows.gif" />'],
	['面积城区统计','<img src="images/directional_arrows.gif" />'],
	['街道年耗电量统计', '<img src="images/directional_arrows.gif" />'],
	['城区年耗电量统计','<img src="images/directional_arrows.gif" />'],
	['功能年耗电量统计', '<img src="images/directional_arrows.gif" />'],
	['年代年耗电量统计', '<img src="images/directional_arrows.gif" />'],
    ['单位面积能耗街道统计','<img src="images/directional_arrows.gif" />'],
	['单位面积能耗城区统计','<img src="images/directional_arrows.gif" />'],
	//['单位面积能耗社区对比','<img src="images/directional_arrows.gif" />'],
	['单位面积能耗功能统计','<img src="images/directional_arrows.gif" />'],
	['单位面积能耗年代统计', '<img src="images/directional_arrows.gif" />'],
//	['建筑总能耗统计', '<img src="images/directional_arrows.gif" />'],
    ['居住建筑单户年单位面积能耗统计', '<img src="images/directional_arrows.gif" />'],
    ['居住建筑楼层年单位面积能耗统计', '<img src="images/directional_arrows.gif" />'],
    ['公共建筑年单位面积能耗统计', '<img src="images/directional_arrows.gif" />'],
    ['大型公共建筑年单位面积能耗统计', '<img src="images/directional_arrows.gif" />'],
    ['居住建筑年单位面积能耗频度统计', '<img src="images/directional_arrows.gif" />'],
    ['政府办公建筑年单位面积能耗频度统计', '<img src="images/directional_arrows.gif" />'],
    ['办公建筑年单位面积能耗频度统计', '<img src="images/directional_arrows.gif" />'],
    ['商场建筑年单位面积能耗频度统计', '<img src="images/directional_arrows.gif" />'],
    ['宾馆饭店建筑年单位面积能耗频度统计', '<img src="images/directional_arrows.gif" />'],
    ['文教建筑年单位面积能耗频度统计', '<img src="images/directional_arrows.gif" />'],
    ['医疗卫生建筑年单位面积能耗频度统计', '<img src="images/directional_arrows.gif" />'],
    ['体育建筑年单位面积能耗频度统计', '<img src="images/directional_arrows.gif" />'],
    ['通信建筑年单位面积能耗频度统计', '<img src="images/directional_arrows.gif" />'],
    ['交通建筑年单位面积能耗频度统计', '<img src="images/directional_arrows.gif" />']
    
];
var functionsGridStore = new Ext.data.SimpleStore({
	fields: [
		{name: 'text'},
		{name: 'ico'}
	]
});
functionsGridStore.loadData(functionsGridData);
function functionsgridrowclick (grid, rowindex, e){
    var responsetext = functionsGridData[rowindex][0];
    clickstatistics(responsetext);
}
function clickstatistics(responsetext) {
    if (!responsetext) {
        return;
    }
	if (responsetext == "显示地图")
	{
		closechart();
		return;
	}
	if (responsetext == "图例")
	{
		toggleScreenOverlay();
		return;
	}
	if (responsetext == "面积街道统计" || responsetext == "面积城区统计")
	{
		showmschart(responsetext);
		return;
	}
	if (responsetext == "街道年耗电量统计" || responsetext == "城区年耗电量统计")
	{
		showstackchart(responsetext);
		return;
	}
	if (responsetext == "单位面积能耗街道统计" || responsetext == "单位面积能耗城区统计" || responsetext == "年代年耗电量统计")
	{
		showchart(responsetext);
		return;
	}
	if (responsetext == "年代年耗电量统计" || responsetext == "单位面积能耗年代统计" || responsetext == "功能年耗电量统计" || responsetext == "单位面积能耗功能统计")
	{
		showchart(responsetext);
		return;
	}
	if (responsetext == "一般公共建筑分功能年单位面积能耗统计" || responsetext == "大型公共建筑分功能年单位面积能耗统计") {
	    showchart("单位面积能耗功能统计",responsetext);
	    return;
	}
	if (responsetext == "建筑总能耗统计") {
	    showlinechart(responsetext);
	    return;
	}
	if (responsetext == "公共建筑年单位面积能耗统计") {
	    showchart(responsetext);
	    return;
	}
	if (responsetext == "大型公共建筑年单位面积能耗统计") {
	    showchart(responsetext);
	    return;
	}
	if (responsetext == "居住建筑楼层年单位面积能耗统计") {
	    showchart(responsetext);
	    return;
	}
	if (responsetext == "居住建筑单户年单位面积能耗统计") {
	    showchart(responsetext);
	    return;
	}
	if (responsetext.indexOf("年单位面积能耗频度统计")) {
	    showchart("功能建筑年单位面积能耗频度统计", responsetext);
	    return;
	}
	
}
var functionsgrid1 = new Ext.grid.GridPanel({
    hideHeaders: true,
	autoHeight: true,
	autoWidth:true,
	store: functionsGridStore,
	columns: [
		//{header: 'pic', width: 80,dataIndex: 'ico'},
		{header: 'textcn',width: '100%', dataIndex: 'text'}//,  display:'table-cell', vertical-align:'middle'
	],
	listeners: {
		rowclick: functionsgridrowclick
	}
});
var functionsgrid = new Ext.tree.TreePanel({
    loader: new Ext.tree.TreeLoader(),
    root: new Ext.tree.AsyncTreeNode({
        expanded: true,
        children: [{
            text: '分街道面积统计',
            value: '面积街道统计',
            leaf: true
        }, {
            text: '分城区面积统计',
            value: '面积城区统计',
            leaf: true
        }, {
            text: '分街道年耗电量统计',
            value: '街道年耗电量统计',
            leaf: true
        }, {
            text: '分城区年耗电量统计',
            value: '城区年耗电量统计',
            leaf: true
        },{
            text: '分功能年耗电量统计',
            value: '功能年耗电量统计',
            leaf: true
        }, 
        {
            text: '分街道年单位面积能耗统计',
            value: '单位面积能耗街道统计',
            leaf: true
        }, {
            text: '分城区年单位面积能耗统计',
            value: '单位面积能耗城区统计',
            leaf: true
        }, {
            text: '分年代年单位面积能耗统计',
            value: '单位面积能耗年代统计',
            leaf: true
        }]
    }),
    rootVisible: false,
    listeners: {
        click: function (n) {
            clickstatistics(n.attributes.value);
        }
    }
});

var functionsgrid2 = new Ext.tree.TreePanel({
    loader: new Ext.tree.TreeLoader(),
    root: new Ext.tree.AsyncTreeNode({
        expanded: true,
        children: [{
            text: '分功能年单位面积能耗统计',
            value: '单位面积能耗功能统计',
            leaf: true
        }, {
            text: '一般公共建筑分功能年单位面积能耗统计',
            value: '一般公共建筑分功能年单位面积能耗统计',
            leaf: true
        }, {
            text: '大型公共建筑分功能年单位面积能耗统计',
            value: '大型公共建筑分功能年单位面积能耗统计',
            leaf: true
        }, {
            text: '居住建筑',
            leaf: false,
            expanded:true,
            children: [
                {
                    text: '分户型年单位面积能耗统计',
                    value: '居住建筑单户年单位面积能耗统计',
                    leaf: true
                },
                {
                    text: '分楼层年单位面积能耗统计',
                    value: '居住建筑楼层年单位面积能耗统计',
                    leaf: true
                },
                {
                    text: '年单位面积能耗频度统计',
                    value: '居住建筑年单位面积能耗频度统计',
                    leaf: true
                }
            ]
        }, {
            text: '公共建筑',
            leaf: false,
            expanded:true,
            children: [{
                text: '政府办公建筑年单位面积能耗频度统计',
                value: '政府办公建筑年单位面积能耗频度统计',
                leaf: true
            }, {
                text: '办公建筑年单位面积能耗频度统计',
                value: '办公建筑年单位面积能耗频度统计',
                leaf: true
            }, {
                text: '商场建筑年单位面积能耗频度统计',
                value: '商场建筑年单位面积能耗频度统计',
                leaf: true
            }, {
                text: '宾馆饭店建筑年单位面积能耗频度统计',
                value: '宾馆饭店建筑年单位面积能耗频度统计',
                leaf: true
            }, {
                text: '文教建筑年单位面积能耗频度统计',
                value: '文教建筑年单位面积能耗频度统计',
                leaf: true
            }, {
                text: '医疗卫生建筑年单位面积能耗频度统计',
                value: '医疗卫生建筑年单位面积能耗频度统计',
                leaf: true
            }, {
                text: '体育建筑年单位面积能耗频度统计',
                value: '体育建筑年单位面积能耗频度统计',
                leaf: true
            }, {
                text: '通信建筑年单位面积能耗频度统计',
                value: '通信建筑年单位面积能耗频度统计',
                leaf: true
            }, {
                text: '交通建筑年单位面积能耗频度统计',
                value: '交通建筑年单位面积能耗频度统计',
                leaf: true
            }]
        }
        ]
    }),
    rootVisible: false,
    listeners: {
        click: function (n) {
            clickstatistics(n.attributes.value);
        }
    }
});

//var fields = ['建筑层数', '建筑类型', '建筑功能', '建筑年代', '建筑结构', '屋顶形式', '玻璃幕墙', '电梯数', '空调数', '户数', '地下室功能', '地下室层数', '节能建筑', '节能改造'];
var fields = ['建筑类型', '建筑功能', '建筑年代', '建筑结构', '屋顶形式', '玻璃幕墙', '电梯数', '空调数', '户数', '地下室功能', '地下室层数', '节能建筑', '节能改造'];
var numfields = ['建筑投影面积', '建筑面积',  '建造年代',  , '电梯数', '空调数', '户数', '太阳能利用', '空调类型', '空调系统类型', '制热量', '地下室层数', '地下室面积', '制冷量', '节能建筑', '节能改造', '单元数'];
var items = getItems(fields);
var querypanel = new Ext.form.FormPanel({
    id: 'googlequeryform',
    labelAlign: 'left',
    frame: true,
    //region: 'center',
    width: '100%',
    //height: '100%',
    autoHeight: true,
    labelWidth: 80,
    autoScroll: true,
    items: items,
    buttonAlign: 'center',
    buttons: [{
        text: '重置查询条件',
        //width: 80,
        handler: function() { Ext.getCmp('googlequeryform').getForm().reset(); }
    }, {
        text: '查询',
        //width: 80,
        handler: function() {
            var googlesouthpanel = Ext.getCmp('googlesouthpanel');
            var queryexpress = "";
            for (var n = fields.length - 1; n >= 0; n--) {
                var itemvalue = Ext.getCmp('queryformitem' + n).getValue().trim();
                if (itemvalue != '') {
                    var checkpoint = 0;
                    for (var m = numfields.length - 1; m >= 0; m--) {
                        //判断是否为number类型
                        if (fields[n] == numfields[m]) {
                            queryexpress = queryexpress == '' ? fields[n] + "=" + itemvalue  : queryexpress + " and " + fields[n] + "=" + itemvalue;
                            checkpoint = 1;
                            break;
                        }
                    }
                    if (checkpoint == 0)
                        queryexpress = queryexpress == '' ? fields[n] + "='" + itemvalue + "'" : queryexpress + " and " + fields[n] + "='" + itemvalue + "' ";
                }
            }
            var itemlevelvalue = Ext.getCmp('queryformitemlevel').getValue();
            //建筑层数不是number
            if (itemlevelvalue != '') {
                switch(itemlevelvalue){
                    case 1:
                        queryexpress = queryexpress == '' ? " 建筑层数<7 " : queryexpress + " and 建筑层数<7 ";
                        break;
                    case 2:
                        queryexpress = queryexpress == '' ? " 建筑层数>=7 and 建筑层数<=18 " : queryexpress + " and 建筑层数>=7 and 建筑层数<=18 ";
                        break;
                    case 3:
                        queryexpress = queryexpress == '' ? " 建筑层数>=19 and 建筑层数<=30 " : queryexpress + " and 建筑层数>=19 and 建筑层数<=30 ";
                        break;
                    case 4:
                        queryexpress = queryexpress == '' ? " 建筑层数>30 " : queryexpress + " and 建筑层数>30 ";
                        break;
                }
                
            }
            var itemvalue = Ext.getCmp('queryformitemtextfield').getValue().trim();
            if (itemvalue != '') {
                queryexpress = queryexpress == '' ? " (建筑地址 like '%" + itemvalue + "%' or 楼幢号 like '%" + itemvalue + "%' or 建筑名称 like '%" + itemvalue + "%') " : queryexpress + " and (建筑地址 like '%" + itemvalue + "%' or 楼幢号 like '%" + itemvalue + "%' or 建筑名称 like '%" + itemvalue + "%') ";
            }
            addgrid(queryexpress);
            ds.setBaseParam('where',queryexpress);
            ds.load({ params: { start: 0, limit: numrecords} });
            googlesouthpanel.doLayout();
            googlesouthpanel.show();
            googlesouthpanel.expand();
        }
}]
    });
function addgrid(queryexpress) {
    var queryconfig = "where=" + queryexpress;
    queryexpress = queryexpress.trim() == "" ? " 建筑年单位面积能耗 is not null" : " 建筑年单位面积能耗 is not null and " + queryexpress + " ";
    var querystatstab = {
        id: 'querystatstabid',
        autoScroll: true,
        autoLoad: { url: 'aspx/querystats.aspx', params: queryconfig },
        //html: '<iframe width="100%" height="100%" src="aspx/querystats.aspx' + queryconfig + '"></iframe>',
        buttonAlign: 'left',
        buttons: [{
            text: '显示月总能耗统计',
            handler: function() { showcchart("aspx/showcpermonthchart.aspx?where=" + queryexpress, "chartdiv"); }
        }, {
            text: '显示月单位面积能耗统计',
            handler: function() { showcchart("aspx/showcperareachart.aspx?where=" + queryexpress, "chartdiv"); }
        }, {
            text: '显示地图',
            handler: function() { closechart(); } 
        }]
    };
    if (Ext.getCmp('querystatstabid')) { Ext.getCmp('querystatstabform').removeAll(); }
    Ext.getCmp('querystatstabform').add(querystatstab);
    Ext.getCmp('querystatstabform').doLayout();
}   
//街道、社区树
/*var tree2 = new Ext.tree.TreePanel({
					border: false,
			        useArrows:true,
			        rootVisible:false,
			        animate:true,
			        enableDD:true,
			        containerScroll: true,
			        root: new Ext.tree.AsyncTreeNode({
                        text: '我是根',
                        draggable:false,//不允许拖拽
                        id:'root1'
                    }),
			        containerScroll: true,
                    //定义json来源文件url
                    loader: new Ext.tree.TreeLoader({
                        dataUrl:'aspx/GetDistrictTree.aspx'
                    }),
			        listeners: {
			        'checkchange': tree2CheckChange
			        }
			    }
			    );	
//城区、街道、社区树选中状态发生改变时触发
function tree2CheckChange(){
    var cnodes = tree2.getChecked();
    var cnodetexts = "";
    for(var i = 0; i < cnodes.length; i++){
        cnodetexts += cnodes[i].text + ",";
    }
    showchart("单位面积能耗社区对比",cnodetexts);
}
*/
var leftpanel = new Ext.Panel({
	region:'west',
	layout:'accordion',
	margins:'5 5 5 5',
	width: 250,
	frame: true,
	defaults: {
		autoScroll: true,
		frame: true
	},
	items: [{
		title: '图层',		
		items: [tree],
		tools: [
            { id: 'print',handler:closechart}
		]
	},{
	    title: '常用统计',
	items: [functionsgrid]
	},
    {
        title: '建筑功能分类统计',
        items: [functionsgrid2]
    },
	/*{
	title: '单位面积能耗社区对比',
		items: [tree2]
	},
    */
	{
	    title: '建筑查询',
	    items: [querypanel]
	}]
});
var viewport;
function resetchart() {
    if (chart != null) {
        var chartd = document.getElementById("chartdiv");
        var width = Ext.getCmp('googlemaplayout').getWidth();
        var height = Ext.getCmp('googlemaplayout').getHeight();
        var chartswf = chart.getAttribute('swf');
        chart = new FusionCharts(chartswf, "ChartId", width, height, "0", "0");
        chart.setDataXML(swfchartdata);
        chart.render("chartdiv");       
    }
}
var focusplacemark;
function queryresultsrowdblclick(grid, rowindex, e) {
    closechart();
    var record = grid.getStore().getRange(rowindex, rowindex)[0];
    var id = record.get('建筑统一编码');
    var dizhi = record.get('建筑地址');
    var name = record.get('建筑名称');
    var chengqu = record.get('城区名称');
    var jiedao = record.get('街道名');
    var shequ = record.get('社区名');
    var x = record.get("POINT_X");
    var y = record.get("POINT_Y");
    var balloon = ge.createHtmlStringBalloon('');
    //放大到该建筑
         
    var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
    lookAt.setLatitude(parseFloat(y));
    lookAt.setLongitude(parseFloat(x));
    lookAt.setRange(500.0);
    if(!focusplacemark){
    focusplacemark = ge.createPlacemark('');            
      //focusplacemark.setName(id);
      ge.getFeatures().appendChild(focusplacemark);
    }
    else{
        ge.getFeatures().removeChild(focusplacemark);
        focusplacemark = ge.createPlacemark('');            
      //focusplacemark.setName(id);
      ge.getFeatures().appendChild(focusplacemark);
    }
    var point = ge.createPoint('');
    x = parseFloat(x);
    y = parseFloat(y);
          point.setLatitude(parseFloat(y));
  point.setLongitude(parseFloat(x));
  focusplacemark.setGeometry(point);
  balloon.setFeature(focusplacemark);
    balloon.setMaxWidth(0);
    balloon.setContentString(name?name: dizhi); //'<IFrame width="400px" height="400px" src="aspx/showinfo.aspx?name=' + id + '"></IFrame>'
    ge.setBalloon(balloon);
    ge.getView().setAbstractView(lookAt);    
}

function viewPlacemark() {
    var bounds = ge.getView().getViewportGlobeBounds();
    var lineStringPlacemark = ge.createPlacemark('');
    
    var lineString = ge.createLineString('');
    lineStringPlacemark.setGeometry(lineString);

    lineString.setExtrude(true);
    lineString.setAltitudeMode(ge.ALTITUDE_RELATIVE_TO_GROUND);

    // Add LineString points
    lineString.getCoordinates().pushLatLngAlt(bounds.getSouth(), bounds.getEast(), 100);
    lineString.getCoordinates().pushLatLngAlt(bounds.getNorth(), bounds.getEast(), 100);
    lineString.getCoordinates().pushLatLngAlt(bounds.getNorth(), bounds.getWest(), 100);
    lineString.getCoordinates().pushLatLngAlt(bounds.getSouth(), bounds.getWest(), 100);
    lineString.getCoordinates().pushLatLngAlt(bounds.getSouth(), bounds.getEast(), 100);

    // Add the feature to Earth
    
    ge.getFeatures().appendChild(lineStringPlacemark);
}
var myMask = null;
function init() {
    
    var fieldsdef = ['建筑统一编码', '建筑名称', '建筑地址', '楼幢号', '建筑投影面积', '建筑面积', '建筑层数', '建筑类型', '建筑功能', '建造年代', '建筑结构', '屋顶形式', '玻璃幕墙', '电梯数', '空调数', '户数', '太阳能利用', '空调类型', '空调开启时间段', '建筑年代', '空调系统类型', '制热量', '地下室功能', '地下室层数', '地下室面积', '制冷量','单元数', '城区名称', '街道名', '社区名', '备注', 'POINT_X', 'POINT_Y', "建筑年单位面积能耗"];
    ds = new Ext.data.JsonStore({
        totalProperty: 'totalcount',
        fields: fieldsdef,
        root: 'root',
        proxy: new Ext.data.HttpProxy({
        url: encodeURI('aspx/query.aspx')
        })
    });
    var columnsdef = new Array();
    for (var n = 0, l = fieldsdef.length; n < l; n++) {
        var headname = fieldsdef[n];
        if (headname == "y07total") headname = "2007年总用电量";
        if (headname == "y08total") headname = "2008年总用电量";
        var tmp = { header: headname, dataIndex: fieldsdef[n] };
        if (headname == "建筑地址") {
            tmp.renderer = function (value, metadata, record) {
                if (record.get("建筑年单位面积能耗")) {
                    return value + ".";
                }
                else
                    return value;
            }
        }
        columnsdef.push(tmp);
    }
    var pagingtoolbar = new Ext.PagingToolbar({
			                    pageSize: numrecords,
			                    store: ds,
			                    displayInfo: true,
			                    beforePageText: "第",
			                    afterPageText: "/{0}页",
			                    firstText: "首页",
			                    prevText: "上一页",
			                    nextText: "下一页",
			                    lastText: "尾页",
			                    refreshText: "刷新",
			                    displayMsg: '当前显示记录从{0}-{1}， 总{2}条记录',
			                    emptyMsg: '没有相关记录!',
			                    doLoad: function(start) {
			                        var o = {}, pn = this.getParams();
			                        o[pn.start] = start;
			                        o[pn.limit] = this.pageSize;
			                        this.store.load({ params: o });

			                    }
			                });

	viewport = new Ext.Viewport({
        layout: 'border',
        items: [
			leftpanel,
			{
			    region: 'center',
			    margins: '5 5 5 0',
			    layout: 'border',
			    items: [
                    {
                        margins: '5 5 5 5',
                        region: 'west',
                        collapsible: true,
                        bodyStyle: 'background:#DFE8F6',
                        id: 'legendlayout',
                        width: 180,
                        title: '图例',
                        html:'<div id="legendsrc"></div>'
                    }, {
			        region: 'center',
			        id: 'googlemaplayout',
			        listeners: {
			            resize: resetchart
			        },
			        html: '<div id="map3d" style="width:100%;height:100%"></div><div style="position:absolute;left:0;top:0;height:100%" id="chartdiv" align="center"></div>'
			    }, {
			        id: 'googlesouthpanel',
			        region: 'south',
			        collapsible: true,
			        collapsed: true, //
			        hidden: true, //
			        height: 280,
			        title: '条件查询',
			        xtype: 'tabpanel',
			        activeTab: 0,
			        items: [{
			            id: 'queryresultstabid',
			            title: '查询结果',
			            layout: 'fit',
			            items: [{
			                xtype: 'grid',
			                store: ds,
			                loadMask: true,
			                stateful: true,
			                stateId: 'grid',
			                columns: columnsdef,
			                listeners: {
			                    rowdblclick: queryresultsrowdblclick
			                },
			                bbar: pagingtoolbar
                        }]
                    }, {
                        id: 'querystatstabform',
                        title: '查询结果统计',
                        layout: 'fit'
			        }]
                }]
            }]
	});
	
    //ds.load({ params: { start: 0, limit: 1} });
	google.earth.createInstance("map3d", initCallback, failureCallback);	myMask = new Ext.LoadMask(Ext.getBody(), { msg: "<a href='javascript:myMask.hide();'><img src='images/welcome.jpg' /></a>", msgCls: 'x' });
	myMask.show();}
var theme = "";
var timer;
var click1 = new Date().getTime();
var click2 = new Date().getTime();
function initCallback(object) {
  ge = object;
  ge.getWindow().setVisibility(true);
  ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
  google.earth.addEventListener(ge.getWindow(), 'click', function(event) {
   // Prevent the default balloon from popping up.
   event.preventDefault();
   return;
   if(event.getTarget().getType() != 'KmlPlacemark'){return;}
   
    click2 = new Date().getTime();
    if((click2 - click1) > 250){
        click1 = click2;
        return;
    }
    else{
        var balloon = ge.createHtmlStringBalloon('');
       balloon.setFeature(event.getTarget());
       balloon.setMaxWidth(500);
        balloon.setContentString(
        '<IFrame width="400px" height="400px" src="aspx/showinfo.aspx?name=' + event.getTarget().getName() + '"></IFrame>');     
       ge.setBalloon(balloon);
    }   
  });
var click3 = false;
  // Listen for mousedown on the window (look specifically for point placemarks).
  google.earth.addEventListener(ge.getWindow(), 'mousedown', function(event) {
    if (event.getTarget().getType() == 'KmlPlacemark') {
      click3 = true;
    }
  });

  // Listen for mousemove on the globe.
  google.earth.addEventListener(ge.getGlobe(), 'mousemove', function(event) {
    click3= false;
  });

  // Listen for mouseup on the window.
  google.earth.addEventListener(ge.getWindow(), 'mouseup', function(event) {
    if(click3){
         var balloon = ge.createHtmlStringBalloon('');
       balloon.setFeature(event.getTarget());
       balloon.setMaxWidth(500);
        balloon.setContentString(
        '<IFrame width="400px" height="400px" src="aspx/showinfo.aspx?name=' + event.getTarget().getName() + '"></IFrame>');     
       ge.setBalloon(balloon);
        click3 = false;
    }
  });
  window.setTimeout(zoomtohangzhou,500);
}
function zoomtohangzhou(){
    var la = ge.createLookAt('');  
    la.set(30.23, 120.14, 2760, ge.ALTITUDE_RELATIVE_TO_GROUND,0, 60, 500);  
    ge.getView().setAbstractView(la);   
    window.setTimeout("tree.root.firstChild.ui.toggleCheck(true)", 500);
}

function failureCallback(object) {
	
}
function removeFeatures(){
    var features = ge.getFeatures()
    var feature = features.getFirstChild();
    while(feature != null)
    {
        features.removeChild(feature);
        feature = features.getFirstChild();
    }
}
function loadkml(name1){
    theme = name1;
    text = "kml.aspx?style=" + name1;
    var location =document.location.href;
    if(location.lastIndexOf('/') == location.length - 1){
        location += text;
    }
    else{
        location = location.substr(0,location.lastIndexOf('/') + 1) + text;
    }
    Ext.get('legendsrc').dom.innerHTML = "<img src='legend/"+name1+".png' ></img>"
    google.earth.fetchKml(ge, location, function (kmlObject) {
        if (kmlObject) {
            kmlobject = kmlObject;
            ge.getFeatures().appendChild(kmlObject);

            if (kmlObject.getAbstractView()) {
                ge.getView().setAbstractView(kmlObject.getAbstractView());
            }
            else {
                var la = ge.createLookAt('');
                la.set(30.23, 120.19, 65460, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 500);
                ge.getView().setAbstractView(la);
                la.set(30.23, 120.19, 55460, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 500);
                ge.getView().setAbstractView(la);
            }
        }
    });
   
}


function toggleScreenOverlay(){
	var chengqulist = kmlobject.getOwnerDocument().getFeatures().getChildNodes();
	var length = chengqulist.getLength();
	for(var i = 0; i < length ; i++){
	    var chengqu = chengqulist.item(i);
	    if (chengqu.getType() == "KmlScreenOverlay")
	    {
	        chengqu.setVisibility(!chengqu.getVisibility());
	        return;
	    }    
	}
}

function setVisible(name,b){
	var chengqulist = kmlobject.getOwnerDocument().getFeatures().getChildNodes();
	var length = chengqulist.getLength();
	for(var i = 0; i < length ; i++){
	    var chengqu = chengqulist.item(i);
	    if (chengqu.getType() == "KmlScreenOverlay")
	        continue;  	
		if(chengqu.getName() == name){
			chengqu.setVisibility(b);
		}			
		var jiedaolist = chengqu.getFeatures().getChildNodes();
		for(var j = 0; j < jiedaolist.getLength(); j++){
			var jiedao = jiedaolist.item(j);
			if(jiedao.getName() == name){
				jiedao.setVisibility(b);
			}		
		}
	}
}
function featureUniqueChecked(node) {
    var root = tree.root;
    for (var n = 0; n < kmllayerslength; n++) {
        if (kmllayerscn[n] != node.text) {
            var rootChild = root.findChild("text", kmllayerscn[n]);
            if (rootChild.ui.isChecked()) {
                var newRootChild = new Ext.tree.TreeNode({
                    text: kmllayerscn[n],
                    checked: false
                });
                //newRootChild.appendChild(new Ext.tree.TreeNode({ hidden: true }));
                root.replaceChild(newRootChild, rootChild);
            }
        }
    }
}
function featureUnchecked(node) {
    var name = node.text;
    var root = tree.root;
    var rootChild = root.findChild("text", name);
    var newRootChild = new Ext.tree.TreeNode({
        text: name,
        checked: false
    });
    //newRootChild.appendChild(new Ext.tree.TreeNode({ hidden: true }));
    root.replaceChild(newRootChild, rootChild);
}
function treeCheckChange(node, checkstatus) {
    var name = node.text;
    for (var n = 0; n < kmllayerslength; n++) {
        if (kmllayerscn[n] == name) {
            if (checkstatus) {
                removeFeatures();
                featureUniqueChecked(node);            
                loadkml(kmllayersen[n]);
                return;
            } else {
                removeFeatures();
                featureUnchecked(node);
                return;
            }
        }
    }
}

function getItems(fields) {
    var items = new Array();
    var item = {
        id: "queryformitemlevel",
        xtype: 'combo',
        width: 120,
        fieldLabel: '建筑层数',
        store: new Ext.data.ArrayStore({
            fields: ['value', 'display'],
            data: [[1, '7层以下'], [2, '7-18层'], [3, '19-30层'], [4, '30层以上']]
        }),
        mode: 'local',
        displayField: 'display',
        valueField: 'value',
        typeAhead: true,
        triggerAction: 'all',
        selectOnFocus: true
    };
    items.push(item);
    for (var n = 0, length = fields.length; n < length; n++) {
        myStore = new Ext.data.JsonStore({
            url: encodeURI("aspx/getDistinctData.aspx?colname="+fields[n]),
            root: 'datastore',
            fields: ['value', 'display']
        });
        myStore.load();
        item = {
            id: "queryformitem"+n,
            xtype: 'combo',
            width: 120,
            fieldLabel: fields[n],
            store: myStore,
            displayField: 'display',
            valueField: 'value',
            typeAhead: true,
            triggerAction: 'all',
            selectOnFocus: true
        };
        items.push(item);
    }
    item = {
        id: 'queryformitemtextfield',
        xtype: 'textfield',
        width: 120,
        fieldLabel: '关键字查询'
    };
    items.push(item);
    return items;
}
function showcchart(url, divid) {
    Ext.Ajax.request({
        url: encodeURI(url),
        success: function(res) { showcpermonthdata(res, divid); },
        failure: fail
    });
    //alert(encodeURI(url));
}
function showcpermonthdata(res, divid) {
    var chartd = document.getElementById(divid);
    chartd.style.display = 'block';
    var width = Ext.getCmp('googlemaplayout').getWidth();
    var height = Ext.getCmp('googlemaplayout').getHeight();
    chart = new FusionCharts("Charts/MSLine.swf", "ChartId", width, height, "0", "0");
    swfchartdata = res.responseText;
    chart.setDataXML(res.responseText);
    chart.render(divid);
			document.getElementById("map3d").style.display = 'none';

}
function showstackchart(url){
	    url = "aspx/" + url;
	    Ext.Ajax.request({
           url: encodeURI(url + ".aspx"),
           success: showstackdata,
           failure: fail
        });
        
	}
    function showstackdata(res){
		var chartd = document.getElementById("chartdiv");
		chartd.style.display = 'block';
		var width = Ext.getCmp('googlemaplayout').getWidth();
		var height = Ext.getCmp('googlemaplayout').getHeight();
		chart = new FusionCharts("Charts/StackedColumn3D.swf", "ChartId", width, height, "0", "0");
		swfchartdata = res.responseText;
		chart.setDataXML(swfchartdata);					   
		chart.render("chartdiv");   
		document.getElementById("map3d").style.display = 'none';
		
		
	}	
	function showmschart(url){
	    url = "aspx/" + url;
	    Ext.Ajax.request({
           url: encodeURI(url + ".aspx"),
           success: showmsdata,
           failure: fail
        });
        
	}
    function showmsdata(res){
		var chartd = document.getElementById("chartdiv");
		chartd.style.display = 'block';
		var width = Ext.getCmp('googlemaplayout').getWidth();
		var height = Ext.getCmp('googlemaplayout').getHeight();
		chart = new FusionCharts("Charts/MSColumn3D.swf", "ChartId", width, height, "0", "0");
		swfchartdata = res.responseText;
		chart.setDataXML(swfchartdata);				   
		chart.render("chartdiv");       
		document.getElementById("map3d").style.display = 'none';
		
		
	}	
	function showchart(url,params1){
	    url = "aspx/" + url + ".aspx";
	    if(params1 != undefined){
	        url += "?params=" +params1;
	    }
	    Ext.Ajax.request({
           url: encodeURI(url),
           success: showdata,
           failure: fail
        });
	}
    function showdata(res){
		var chartd = document.getElementById("chartdiv");
		chartd.style.display = 'block';
		var width = Ext.getCmp('googlemaplayout').getWidth();
		var height = Ext.getCmp('googlemaplayout').getHeight();
		chart = new FusionCharts("Charts/Column3D.swf", "ChartId", width, height, "0", "0");
		swfchartdata = res.responseText;
		chart.setDataXML(swfchartdata);					   
		chart.render("chartdiv");
		document.getElementById("map3d").style.display = 'none';
}
function showlinechart(url) {
    url = "aspx/" + url;
    Ext.Ajax.request({
        url: encodeURI(url + ".aspx"),
        success: showlinedata,
        failure: fail
    });

}
function showlinedata(res) {
    var chartd = document.getElementById("chartdiv");
    chartd.style.display = 'block';
    var width = Ext.getCmp('googlemaplayout').getWidth();
    var height = Ext.getCmp('googlemaplayout').getHeight();
    chart = new FusionCharts("Charts/Line.swf", "ChartId", width, height, "0", "0");
    swfchartdata = res.responseText;
    chart.setDataXML(swfchartdata);
    chart.render("chartdiv");
			document.getElementById("map3d").style.display = 'none';

}		
function showpiechart(url){
	    url = "aspx/" + url;
	    Ext.Ajax.request({
           url: encodeURI(url + ".aspx"),
           success: showpiedata,
           failure: fail
        });
        
	}
    function showpiedata(res){
		var chartd = document.getElementById("chartdiv");
		chartd.style.display = 'block';
		var width = Ext.getCmp('googlemaplayout').getWidth();
		var height = Ext.getCmp('googlemaplayout').getHeight();
		chart = new FusionCharts("Charts/Doughnut3D.swf", "ChartId", width, height, "0", "0");
		swfchartdata = res.responseText;
		chart.setDataXML(swfchartdata);					   
		chart.render("chartdiv");    
		document.getElementById("map3d").style.display = 'none';		
		
	}			
	function fail(res){
	    alert(res.responseText);
	}
	function closechart(){
		var chartd = document.getElementById("chartdiv");
		chartd.style.display = 'none';
		document.getElementById("map3d").style.display = 'block';		

	}
    </script>
  </head>
  <body onload='init()'>
  
  </body>
</html>